package April._25.answer;

import java.lang.reflect.Field;

public class Work2 {
    public static void setAll(Object targetObj, String fieldName, Object newValue) {

    }

    public class Work1 {
        public static void setAll(Object targetObj, String fieldName, Object newValue) throws NoSuchFieldException, IllegalAccessException {
            // 拿到字节码文件对象
            Class c = targetObj.getClass();
            // 获取成员变量对象
            Field field = c.getDeclaredField(fieldName);
            // 赋值
            ((Field) field).setAccessible(true);
            field.set(targetObj, newValue);

        }
    }
}